using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PokerLearner.Poker;

namespace PokerLearner.Server
{
	public partial class FormStart : Form
    {
        private int blinds;

        public FormStart()
		{
			InitializeComponent();
		}

		private void buttonStart_Click(object sender, EventArgs e)
		{
			PokerServer.Instance.Start(blinds);
			this.Close();
		}

        private void textBoxBlinds_TextChanged(object sender, EventArgs e)
        {
            // Check that input is integer as expected.
            string blindsStr = ((System.Windows.Forms.TextBox)sender).Text;
            blindsInvalid.Clear();
            blinds = 0;
            if (blindsStr.Length == 0)
            {
                buttonStart.Enabled = false;
            }
            else if (int.TryParse(blindsStr, out blinds) == false)
            {
                blindsInvalid.SetError(textBoxBlinds, "Integer required");
                buttonStart.Enabled = false;
            }
            else
            {
                if (blinds <= 0)
                {
                    blindsInvalid.SetError(textBoxBlinds, "Should be greater than 0");
                    buttonStart.Enabled = false;
                }
                else
                {
                    buttonStart.Enabled = true;
                }
            }
        }
	}
}